home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0017_VOL-ID.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  75 lines

  1. {
  2.  In the thread concerning copy protection (in which I have no
  3.  interest) the serial number of a disk was mentioned.
  4.  How can this be read from TP? Can it be changed other than
  5.  by re-Formatting? I can't find any reference to serial number
  6.  in the Dos 5.0 users guide except a passing one in the section
  7.  on the ForMAT command.
  8.  
  9. Reading the volume id number is no problem:
  10.  
  11. reads volume id number -- not sophisticated enough to
  12. determine whether disk was Formatted With a Dos version
  13. new enough to assign volume id }
  14.  
  15. Uses Dos;
  16.  
  17. Function Byte2HexSt(b : Byte) : String;
  18. Const
  19.   hexChars: Array [0..$F] of Char =
  20.     '0123456789ABCDEF';
  21. begin
  22.   Byte2HexSt := hexChars[b shr 4] + hexChars[b and $F];
  23. end;
  24.  
  25. Procedure ResetDisk(DriveNo : Byte);
  26. Var
  27.   reg : Registers;
  28. begin
  29.   reg.ah := 0;        { bios Function reset drive system }
  30.   reg.dl := DriveNo;
  31.   intr($13,reg);
  32. end;
  33.  
  34. Function VolIDSt(DriveCh : Char) : String;
  35. { returns Volume ID number as a String of hex digits }
  36. Var
  37.   reg : Registers;
  38.   try : Integer;
  39.   buff : Array[0..1023] of Byte;
  40. begin
  41.   DriveCh := upCase(DriveCh);
  42.   try := 0;
  43.   Repeat
  44.     reg.ax := $0201;  { ah = bios Function read disk sector }
  45.                       { al = read 1 sector }
  46.     reg.cx := $0001;  { ch = cylinder number }
  47.                       { cl = sector number }
  48.     reg.dh := 0;      { head number }
  49.     reg.dl := ord(DriveCh) - 65;  { drive number }
  50.     reg.es := seg(buff);
  51.     reg.bx := ofs(buff);
  52.     intr($13,reg);
  53.     inc(try);
  54.     if reg.flags and FCarry <> 0 then ResetDisk(reg.dl);
  55.   Until ((reg.flags and FCarry) = 0) or (try = 3);
  56.   if reg.flags and FCarry <> 0
  57.     then VolIDSt := 'Error attempting to read volume ID number'
  58.     else VolIDSt := Byte2HexSt(buff[$2A]) +
  59.                     Byte2HexSt(buff[$29]) + '-' +
  60.                     Byte2HexSt(buff[$28]) +
  61.                     Byte2HexSt(buff[$27]);
  62. end;
  63.  
  64. {
  65. Can the volume id number be changed?  You bet.
  66.  
  67. Although it is True that DISKCOPY will not copy the volume id
  68. number from the original disk, it's still a pretty weak basis For a
  69. copy protection scheme.  I consider myself a pretty unsophisticated
  70. Programmer, but it only took me a few minutes of fooling around to
  71. figure out where the volume id number is on the disk.  then all you
  72. have to do is grab an interrupt reference and quickly Type up some
  73. code to read and Write to the right spot on the disk.
  74. }
  75.